package chapter21;



import chapter20.Circle;
import chapter20.GeometricObject;
import chapter20.GeometricObjectCompartor;
import chapter20.Rectangle;

import java.util.Set;
import java.util.TreeSet;

/**
 * @program: exercise
 * @description: 演示使用comparator接口来对树形集中的元素进行排序操作
 * @author: 陈庆彪
 * @create: 2020-02-23 11:33
 **/
public class TestTreeSetWithComparator {
    public static void main(String[] args) {
        Set<GeometricObject> set=new TreeSet<>(new GeometricObjectCompartor());
        set.add(new Rectangle(4,5));
        set.add(new Circle(40));
        set.add(new Circle(40));
        set.add(new Rectangle(4,1));

        System.out.println("图形面积排序：");
        for (GeometricObject element: set){
            System.out.println("area="+element.getArea());
        }
    }
}
